package com.yanqu.road.server.cmd.newmonopolymkt;

import com.yanqu.road.entity.enums.eMailType;
import com.yanqu.road.entity.player.UserInfo;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.newmonopolymkt.NewMonopolyMarketProto;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.Command;
import com.yanqu.road.server.logic.mail.MailManager;
import com.yanqu.road.server.manger.MultipleLanguageMgr;
import com.yanqu.road.server.manger.player.UserMgr;
import com.yanqu.road.server.manger.systemgroup.newmonopolymarket.NewMonopolyMarketMgr;
import com.yanqu.road.server.protocol.GameProtocol;
import io.netty.channel.ChannelHandlerContext;

@Cmd(code = GameProtocol.S_NEW_MONOPOLY_MARKET_AUTO_SEND_RANK_REWARD_FROM_CROSS, desc = "跨服自动发奖")
public class NewMonopolyMarketAutoSendRewardSyncCmdFromCross implements Command {

    @Override
    public void execute(ChannelHandlerContext ctx, YanQuMessage yanQuMessage) throws Exception {
        NewMonopolyMarketProto.NewMonopolyMarketAutoSendRewardSync sync = NewMonopolyMarketProto.NewMonopolyMarketAutoSendRewardSync.parseFrom(yanQuMessage.getBytes());
        for (NewMonopolyMarketProto.NewMonopolyMarketAutoSendReward sendReward : sync.getRankList()) {
            UserInfo userInfo = UserMgr.getUserInfo(sendReward.getUserId());
            if(userInfo == null){
                continue;
            }
            String language = userInfo.getLanguage();
            String mailTitle = MultipleLanguageMgr.getContent(MailManager.MONOPOLYMARKEYT_RANK_REWARD_TITLE, language);
            String mailContent = MultipleLanguageMgr.getContent(MailManager.MONOPOLYMARKEYT_RANK_REWARD_CONTENT, language);
            MailManager.sendMail(userInfo.getUserId(), eMailType.SYSTEM.getValue(), sendReward.getReward(), mailContent, mailTitle);
            NewMonopolyMarketMgr.getLogger().info("new monopoly auto reward type {}, userId {}, rank {}, reward {}", sync.getType(), userInfo.getUserId(), sendReward.getRank(), sendReward.getReward());
        }
    }
}
